<?php
/**
 * The Camelizer class provides string Camelization services (to understand what
 * camelize means think at the camel). For instance, the camelized version
 * of 'iwantmore' is 'iWantMore'.
 *
 * @author Jérôme Bogaerts <jerome.bogaerts@tudor.lu>
 * @package util
 */
class Camelizer
{
	/**
	 * Puts together a multiplicity of string in a camelized version.
	 * e.g : using {'i', 'want', 'more'} as parameter, the camelize function
	 * will return 'iWantMore'.
	 *
	 * @param array $strings An array of string that must be put together in a camelized version.
	 */
	public static function camelize(array $strings, $firstToUpper = false)
	{
		$firstDone = false;
		$camelized = '';
		
		foreach ($strings as $string)
		{
			if (!firstDone)
			{
				$camelized .= (!$firstToUpper) ? self::firstToLower($string) : self::firstToUpper($string);
				$firstDone = true;
			}
			else
			{
				$camelized .= self::firstToUpper($string);
			}
		}
		
		return $camelized;
	}
	
	/**
	 * Changes the first character of a string in its capital version.
	 * e.g : 'bilibu' becomes 'Bilibu'.
	 *
	 * @param string $string The string to modify.
	 * @return string The string with its first character in a capital version.
	 */
	public static function firstToUpper($string)
	{
		return strtoupper(substr($string, 0, 1)) . substr($string, 1);
	}
	
	/**
	 * Changes the first character of a string in its lower version.
	 * e.g : 'Bilibu' becomes 'bilibu'.
	 *
	 * @param string $string The string to modify.
	 * @return string The string with its first character in a capital version.
	 */
	public static function firstToLower($string)
	{
		return strtolower(substr($string, 0, 1)) . substr($string, 1);
	}
}
?>